<template>
<el-form :model="editForm"  label-width="120px" :rules="editFormRules" ref="editFormRef">
    <el-form-item label="主键" prop="id">
        <el-input  v-model="editForm.id" placeholder="主键" :maxlength="64" @change="editSomeFields(editForm,'id',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="菜单名称" prop="name">
        <el-input  v-model="editForm.name" placeholder="菜单名称" :maxlength="100" @change="editSomeFields(editForm,'name',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="排序" prop="sort">
        <el-input  v-model="editForm.sort" placeholder="排序" :maxlength="10" @change="editSomeFields(editForm,'sort',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="云用户机构编号" prop="branchId">
        <el-input  v-model="editForm.branchId" placeholder="云用户机构编号" :maxlength="50" @change="editSomeFields(editForm,'branchId',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="创建人" prop="cuserid">
        <el-input  v-model="editForm.cuserid" placeholder="创建人" :maxlength="64" @change="editSomeFields(editForm,'cuserid',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="创建时间" prop="cdate">
        <el-date-picker type="date" placeholder="选择日期"  v-model="editForm.cdate"  value-format="yyyy-MM-dd HH:mm:ss" format="yyyy-MM-dd" @change="editSomeFields(editForm,'cdate',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="访问路径,路由则填写路由的path" prop="accUrl">
        <el-input  v-model="editForm.accUrl" placeholder="访问路径,路由则填写路由的path" :maxlength="250" @change="editSomeFields(editForm,'accUrl',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="菜单图标" prop="icon">
        <el-input  v-model="editForm.icon" placeholder="菜单图标" :maxlength="20" @change="editSomeFields(editForm,'icon',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="菜单类型1-路由，2-自定义" prop="stype">
        <el-input  v-model="editForm.stype" placeholder="菜单类型1-路由，2-自定义" :maxlength="10" @change="editSomeFields(editForm,'stype',$event)" :disabled="disField"/>
    </el-form-item>
    <el-form-item label="菜单类型为路由时，填写路由的name" prop="rname">
        <el-input  v-model="editForm.rname" placeholder="菜单类型为路由时，填写路由的name" :maxlength="255" @change="editSomeFields(editForm,'rname',$event)" :disabled="disField"/>
    </el-form-item>
</el-form>
<el-row v-if="showBtn!==false" class="footer">
    <el-button @click="close" icon="close">关闭</el-button>
    <el-button icon="submit" v-if="currOpType=='add'|| (currOpType=='edit' && someOpen==false)" v-loading="load.edit" type="primary" @click="saveSubmit" :disabled="disBtn('addBtn') || !checkBtnQx('addBtn',menuDefId) || load.edit">提交</el-button>
</el-row>
</template>

<script>
import * as MenuFavoriteApi from '@/api/mdp/menu/menuFavorite';
import { MdpFormMixin } from '@/components/mdp-ui/mixin/MdpFormMixin.js';
import { mapState } from 'pinia'
import { useUserStore } from '@/store/modules/user'

export default {
    name:'MenuFavoriteForm',
    mixins:[MdpFormMixin],
    components: {
    },
    computed: {
        ...mapState(useUserStore,['userInfo'])
    },
    props:{
    },
    watch: {
    },
    data() {
        return {
            menuDefId:'',//menu_def.id 菜单表菜单编号，用于按钮权限判断
            pkNames:["id"],//表格主键的java属性名称，驼峰命名，默认为id,支持多主键
            currOpType:'add',//表单 add、edit，所有按钮可动、detail-只看不能操作
            editFormRules: {
                id:[
                //{ required: true, message: '此项必填', trigger: 'change' },
                //{ min: 1,max: 200, message: '长度在1到200之间', trigger: 'change'}
                ]
            },
            editForm: {
                id:'',name:'',sort:'',branchId:'',cuserid:'',cdate:'',accUrl:'',icon:'',stype:'',rname:''
            },
            //增删改查(含批量)接口
            apis:{
                queryById: MenuFavoriteApi.queryMenuFavoriteById,
                add: MenuFavoriteApi.addMenuFavorite,
                edit: MenuFavoriteApi.editMenuFavorite,
                editSomeFields: MenuFavoriteApi.editSomeFieldsMenuFavorite
            },
        }
    },
    methods: {
         //由组件扩展添加其它的初始页面的逻辑(mounted+onOpen都会调用此函数，建议只添加公共逻辑)
         initCurrData(){

         },
        /**
         * 检查参数是否满足调用后台接口的条件
         * @returns true / false
         */
        preParamCheck(params){
            return true;
        },
        /**
         * 对修改的字段进行判断，返回false ,将取消更新数据库,由组件扩展
         * @param {*} row 当前选中的行
         * @param {*} fieldName 修改的字段名
         * @param {*} $event 修改后的值
         * @param {*} params 将要提交服务器的参数
         * @returns true/false 返回false ,将取消更新数据库
         */
        editSomeFieldsCheck(row,fieldName,$event,params){
            if(this.editable==false){
                return false;
            }
            params[fieldName]=$event
            return true;
        },
    },
    mounted() {

    }
}

</script>

<style scoped>

</style>